package com.vipheyue.huaxue.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.orhanobut.logger.Logger;
import com.vipheyue.huaxue.R;
import com.vipheyue.huaxue.bean.EventBean;
import com.vipheyue.huaxue.utils.GlideLoader;
import com.vipheyue.huaxue.utils.GsonUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class DetailMessageActivity extends AppCompatActivity {

    @Bind(R.id.tv_title)
    TextView tv_title;
    @Bind(R.id.tv_updateTime)
    TextView tv_updateTime;
    @Bind(R.id.tv_desc)
    TextView tv_desc;
    EventBean job;
    @Bind(R.id.iv_Menu_leftImg)
    ImageView iv_Menu_leftImg;
    @Bind(R.id.tv_Menu_leftTitle)
    TextView tv_Menu_leftTitle;
    @Bind(R.id.rl_menu_left)
    RelativeLayout rl_menu_left;
    @Bind(R.id.tv_Menu_Title)
    TextView tv_Menu_Title;
    @Bind(R.id.iv_menu_rightTitle)
    TextView iv_menu_rightTitle;
    @Bind(R.id.iv_menu_right)
    ImageView iv_menu_right;
    @Bind(R.id.rl_menu_right)
    RelativeLayout rl_menu_right;
    @Bind(R.id.iv_img)
    ImageView iv_img;
    @Bind(R.id.btn_down)
    Button btn_down;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail_message);
        ButterKnife.bind(this);
        initData();
    }

    private void initData() {
        tv_Menu_Title.setText("正文");
        Intent intent = this.getIntent();
        String jobStr = intent.getStringExtra("jobStr");
        Logger.i("jobStr" + jobStr);
        job = GsonUtils.fromJson(jobStr, EventBean.class);
        tv_title.setText(job.getTitile());
        tv_updateTime.setText(job.getUpdatedAt());
        tv_desc.setText(job.getDecs());
//        Glide.with(this).load("http://heyue.oss-cn-hangzhou.aliyuncs.com/AppData/bigbusiness/1.jpg").into(iv_img);
        GlideLoader.showImg(this, job.getImgFileUri(), iv_img);
    }


    @OnClick({R.id.rl_menu_left, R.id.btn_down})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_menu_left:
                finish();
                break;
            case R.id.btn_down:
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_uri = Uri.parse(job.getAttachmentFileUri());
                intent.setData(content_uri);
                startActivity(intent);
                break;
        }
    }
}
